package com.test07_继承与多态;

import org.junit.Test;

/**
 * Object类
 */
public class YootkDemo_06 {

    @Test
    public void test1() {
        Object obj = "沐言优拓：www.yootk.com";
        if (obj instanceof String) {
            String message = (String) obj;
            System.out.println(message.toUpperCase());
        }
    }

    @Test
    public void test2() {
        Book6 bookA = new Book6("Java从入门到项目实战", "李兴华", 99.8);
        Book6 bookB = new Book6("Java从入门到项目实战", "李兴华", 99.8);
        if (bookA.equals(bookB)) {
            System.out.println("【√】当前两个对象的内容相等。");
        } else {
            System.out.println("【×】当前两个对象的内容不等。");
        }
    }
}

class Book6 {
    private String title;
    private String author;
    private double price;

    public Book6(String title, String author, double price) {
        this.title = title;
        this.author = author;
        this.price = price;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof Book6)) {
            return false;
        }
        Book6 book = (Book6) obj;
        return this.title.equals(book.title) && this.author.equals(book.author) && this.price == book.price;
    }

    @Override
    public String toString() {
        return "【Book-" + super.toString() + "】图书名称：" + this.title + "、图书作者：" + this.author + "、图书价格：" + this.price;
    }
}
